package com.wq.myspring.postprocessor;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @PackageName: com.wq.myspring.postprocessor
 * @ClassName MyBeanDefinitionPostProcessor
 * @Description: TODO 自定义BeanDefinitionPostProcessor
 * @Author Wenqiang
 * @Date 2021/07/17 23:26
 * @Version V1.0
 */
@Component
public class MyBeanDefinitionPostProcessor implements BeanDefinitionRegistryPostProcessor {

	@Override
	public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
		//定义一个Noo的beandifiniton对象
		AbstractBeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition().getBeanDefinition();
		//注意此处beanclass属性不要设置错了
		beanDefinition.setBeanClass(Noo.class);
		registry.registerBeanDefinition("noo", beanDefinition);
	}

	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
		//	空实现
	}
}
